package com.mmd.manage.web;


import com.mmd.bean.CODE;
import com.mmd.bean.WebJsonBean;
import com.mmd.exception.GameException;
import com.mmd.manage.service.FeeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping(value = "/api/fee")
@Controller
public class FeeController {
	
	@Autowired
	private FeeService feeService;

	@RequestMapping(value = "/computeTotalFee")
	@ResponseBody
	public WebJsonBean computeTotalFee(Float weight, Long areaId, Long modeId, String hscode, Integer type){
		if (weight == null){
			throw new GameException(new CODE(9999, "请输入重量"));
		}
		if (areaId == null){
			throw new GameException(new CODE(9999, "请选择区域"));
		}
		if (modeId == null){
			throw new GameException(new CODE(9999, "请选择模式"));
		}
		if (StringUtils.isEmpty(hscode)){
			throw new GameException(new CODE(9999, "请输入hscode"));
		}
		//0-非独清关, 1-单独清关
		return new WebJsonBean(CODE.SUCCESS, feeService.computeTotalFee(weight, areaId, modeId, hscode, type));
	}
	
	@RequestMapping(value = "/getSonAreaList")
	@ResponseBody
	public WebJsonBean getSonAreaList() {
		return new WebJsonBean(CODE.SUCCESS, feeService.getSonAreaList());
	}

	@RequestMapping(value = "/getAreaList")
	@ResponseBody
	public WebJsonBean getAreaList() {
		return new WebJsonBean(CODE.SUCCESS, feeService.getAreaList());
	}
}
